package day05

import org.apache.spark.broadcast.Broadcast
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object BoradcastDemo {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setAppName("broadcast").setMaster("local[2]")
    val sc = new SparkContext(conf)
    val data: RDD[String] = sc.textFile("hdfs://master:9000/Wordcount3/input/one.txt")
    val arr1 = Array("xue","xi","tian")
    //用sc.broadcast(变量)得到广播变量；广播变量用value得到值。
    val broadcastData: Broadcast[Array[String]] = sc.broadcast(arr1)
    val filtered: RDD[String] = data.filter(broadcastData.value.contains(_))
    println(filtered.collect().toBuffer)
    sc.stop()
  }
}
